import { register } from '../services/user';
import { setToken, setUid } from '../utils/token';

export default {
  namespace: 'register',

  state: {},

  effects: {
    *submit({ payload }, { call }) {
      const response = yield call(register, payload.params);
      if (response.isRight) {
        const { access_token: token, expire_at: expired, uid } = response.body;
        setToken(token, expired);
        setUid(uid);
        payload.onSuccess();
      }
    },
  },

  reducers: {},
};
